/*
 * @Description  : 登录模块 redux
 * @Author       : Keyman
 * @Date         : 2025-11-08 22:39:51
 * @LastEditors  : Keyman
 * @LastEditTime : 2025-11-28 13:57:27
 */

import { createSlice } from "@reduxjs/toolkit";

export const authSlice = createSlice({
  name: "auth",
  initialState: {
    token: sessionStorage.getItem("token") || null,
    menuList: [],
  },
  reducers: {
    setToken(state, action) {
      state.token = action.payload; // 把 token 存到 redux 中
      sessionStorage.setItem("token", action.payload);
    },

    clearToken: (state) => {
      state.token = null;
      sessionStorage.removeItem("token");
    },

    setMenu: (state, action) => {
      state.menuList = action.payload;
    },
  },
});

export const { setToken, clearToken, setMenu } = authSlice.actions;
export default authSlice.reducer;
